package stream;

import java.util.Optional;
import java.util.stream.Stream;

public class StreamOptional {
    public static void main(String[] args) {
        //求流中最大值 最小值
        Optional<Integer> max = Stream.of(8, 3, 6, 8).max((a, b) -> a - b);
        System.out.println(max.get());

        Optional<Integer> min = Stream.of(8, 3, 6, 8).min((a, b) -> a - b);
        System.out.println(min.get());

        //first和any都是找第一个元素
        Optional<Integer> first = Stream.of(8, 3, 6, 8).findFirst();
        System.out.println(first.get());
        Optional<Integer> any = Stream.of(6, 3, 6, 8).findFirst();
        System.out.println(any.get());
    }
}
